use nalgebra::Point2;

// 道具类型
#[derive(Debug, Clone, Copy)]
pub enum GamePropType {
    Health,     // 生命值恢复
    Invincible, // 临时无敌
    Range,      // 攻击范围扩大
    Speed,      // 移动速度提升
    Damage,     // 伤害值增加
}

// 道具结构
pub struct GameProp {
    pub position: Point2<f32>,
    pub game_prop_type: GamePropType,
    pub duration: f32,       // 持续时间
    pub value: f32,          // 效果值
    pub active: bool,        // 是否激活
    pub respawn_time: f32,   // 重生时间
    pub current_respawn: f32,// 当前重生计时
    pub collected: bool,     // 是否被收集
}

impl GameProp {
    pub fn new(position: Point2<f32>, game_prop_type: GamePropType) -> Self {
        GameProp {
            position,
            game_prop_type,
            duration: match game_prop_type {
                GamePropType::Health => 0.0, // 立即生效
                GamePropType::Invincible => 5.0,
                GamePropType::Range => 10.0,
                GamePropType::Speed => 8.0,
                GamePropType::Damage => 12.0,
            },
            value: match game_prop_type {
                GamePropType::Health => 50.0,
                GamePropType::Invincible => 0.0,
                GamePropType::Range => 1.5,
                GamePropType::Speed => 1.3,
                GamePropType::Damage => 1.4,
            },
            active: true,
            respawn_time: 30.0, // 30秒后重生
            current_respawn: 0.0,
            collected: false,
        }
    }
    
    // 更新道具状态
    pub fn update(&mut self, dt: f32) {
        if !self.active {
            self.current_respawn += dt;
            if self.current_respawn >= self.respawn_time {
                self.active = true;
                self.current_respawn = 0.0;
                self.collected = false;
            }
        }
    }
    
    // 收集道具
    pub fn collect(&mut self) -> bool {
        if self.active && !self.collected {
            self.collected = true;
            self.active = false;
            true
        } else {
            false
        }
    }
    
    // 获取道具价值（用于AI评估）
    pub fn get_value(&self) -> f32 {
        match self.game_prop_type {
            GamePropType::Health => self.value * 0.5, // 生命值道具价值根据当前生命值调整
            GamePropType::Invincible => self.value * 2.0,
            GamePropType::Range => self.value * 1.5,
            GamePropType::Speed => self.value * 1.3,
            GamePropType::Damage => self.value * 1.4,
        }
    }
}